import 'package:flutter/widgets.dart';
import 'package:website.core/core/presentation/widgets/stateful_wloc.dart';

class WlocBuilder<W extends StatefulWloc<S, dynamic>, S> extends StatelessWidget {
  const WlocBuilder({
    required this.wloc,
    required this.builder,
    Key? key,
  }) : super(key: key);

  final W wloc;
  final Widget Function(BuildContext context, S state) builder;

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
      initialData: wloc.initialState,
      stream: wloc.stream,
      builder: (context, AsyncSnapshot<S> snapshot) {
        return builder(context, snapshot.data!);
      },
    );
  }
}
